/**
 * Class: Dot2D
 *
 * Purpose: 
 *
 * Created: Jan 27, 2010 @ 9:37:10 AM
 * @author Ken Scott
 */
package org.openfantasia.ps.shape;

import org.openfantasia.ps.particle.Particle;
import org.openfantasia.ui.PFrame;
import org.openfantasia.util.math.DPoint3;
import org.openfantasia.util.math.PMath;

public class Wave extends Shape {

	public static final String XREZ = "x_rez";

	public static final String YREZ = "y_rez";

	public static final String MODULATION = "modulation";

	private boolean drawDots = true;

	private boolean drawLines = false;

	private double xRez = 10;

	private double yRez = 10;

	private DPoint3 modulation = new DPoint3();


	public Wave(PFrame frame) {
		super(frame);
	}


	public Wave(PFrame frame, double weight, double xRez, double yRez, DPoint3 modulation) {
		super(frame, new DPoint3(1, 1, 1));
		setLineWeight(weight);
		setXRez(xRez);
		setYRez(yRez);
		setModulation(modulation);
	}


	public void drawShape(Particle particle) {
		DPoint3 size = getSize(particle);
		double time = getTime();

		if (drawLines) {
			frame.beginShape(frame.LINES);
		}
		else if (drawDots) {
			frame.beginShape(frame.POINTS);
		}

		double xRadius = size.getX();
		double yRadius = size.getY();
		double zRadius = size.getZ();

		double xSteps = getXRez(particle);
		for (double x = 0; x < xSteps; x++) {
			DPoint3 prev = null;
			double xAngle = PMath.PI * x / xSteps;

			double ySteps = getYRez(particle);
			for (double y = 0; y <= ySteps; y++) {
				double yAngle = PMath.TWO_PI * y / ySteps;

				double px = xRadius * Math.sin(xAngle);
				double py = yRadius * Math.sin(yAngle);
				double pz = 0;
				DPoint3 loc = new DPoint3(px, py, pz);

				if (drawLines && (prev != null)) {
					frame.line(loc, prev);
				}

				if (drawDots) {
					frame.point(loc);
				}

				prev = loc;
			}
		}
		frame.endShape();
	}


	public boolean isDrawDots() {
		return drawDots;
	}


	public void setDrawDots(boolean drawDots) {
		this.drawDots = drawDots;
	}


	public boolean isDrawLines() {
		return drawLines;
	}


	public void setDrawLines(boolean drawLines) {
		this.drawLines = drawLines;
	}


	public double getXRez() {
		return xRez;
	}


	public double getXRez(Particle particle) {
		return (Double) getBehaviorValue(XREZ, particle, getTime(), getXRez());
	}


	public void setXRez(double xRez) {
		this.xRez = xRez;
	}


	public double getYRez() {
		return yRez;
	}


	public double getYRez(Particle particle) {
		return (Double) getBehaviorValue(YREZ, particle, getTime(), getYRez());
	}


	public void setYRez(double yRez) {
		this.yRez = yRez;
	}


	public DPoint3 getModulation() {
		return modulation;
	}


	public DPoint3 getModulation(Particle particle) {
		return (DPoint3) getBehaviorValue(MODULATION, particle, getTime(), getModulation());
	}


	public void setModulation(DPoint3 modulation) {
		this.modulation = modulation;
	}
}